//
//  UIImage+KR.m
//  KEREN
//
//  Created by MW on 2023/3/13.
//

#import "UIImage+KR.h"

@implementation UIImage (KR)

+ (UIImage *)setMainbackImage{
    UIView *backView = [[UIView alloc] initWithFrame:UIApplication.sharedApplication.delegate.window.frame];
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)[UIColor redColor].CGColor, (__bridge id)[UIColor yellowColor].CGColor, (__bridge id)[UIColor blueColor].CGColor];
    gradientLayer.locations = @[@0, @1.0];
    gradientLayer.startPoint = CGPointMake(0, 0.5);
    gradientLayer.endPoint = CGPointMake(1, 0);
    gradientLayer.frame = UIApplication.sharedApplication.delegate.window.frame;
    
    CAGradientLayer *gradientLayers = [CAGradientLayer layer];
    gradientLayers.colors = @[(__bridge id)[UIColor redColor].CGColor, (__bridge id)[UIColor yellowColor].CGColor, (__bridge id)[UIColor blueColor].CGColor];
    gradientLayers.locations = @[@0, @1.0];
    gradientLayers.startPoint = CGPointMake(0, 0.5);
    gradientLayers.endPoint = CGPointMake(1, 1);
    gradientLayers.frame = UIApplication.sharedApplication.delegate.window.frame;
    [backView.layer addSublayer:gradientLayer];
    [backView.layer addSublayer:gradientLayers];

    return  [UIImage snapshotWithView:backView];
}

+ (UIImage *)snapshotWithView:(UIView *)view {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
@end
